﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SecurityBLL;
using Model.Security.FindEntityInfo;
using Util;
using Model.BusinessLogic.EntityInfo;

public partial class LoginSign : System.Web.UI.Page
{
    private LoginBLL loginBLL = new LoginBLL();            //登录变量
    private Menu menu = new Menu();                        //菜单变量
    protected void Page_Load(object sender, EventArgs e)
    {
        string name = Request["Name"].ToString();           //获取出过来的Name变量
        string password = Request["Password"].ToString();   //获取传送过来的Password变量
        this.UserLogin(name,password);
    }

    protected void UserLogin(string name,string password)
    {
        DataSet userDs = new DataSet();                                     //存储查询的记录集
        DataTable getNianFen = new DataTable();            //存储年份数据集
        try
        {
            userDs = loginBLL.YongHuDengLu(name, password); //根据用户名和密码返回记录集
            getNianFen = loginBLL.GetNianFenTable();                //得到年份数据集
            DataTable userDt = userDs.Tables[0];                    //取第0行的数据
            if (userDt != null && userDt.Rows.Count > 0)
            {
                Hashtable hs = new Hashtable();                     //申请哈希表变量，存放权限
                Session["SalesId"] = userDt.Rows[0]["RY_SourceID"].ToString();        //存储RY_SourceID
                Session["BM_MingCheng"] = userDt.Rows[0]["BM_MingCheng"].ToString();  //存储部门名称
                Session["UserName"] = userDt.Rows[0]["RY_DengLuMing"].ToString();     //存储登录名
                Session["RY_ID"] = userDt.Rows[0]["RY_ID"].ToString();                //存储人员id号
                Session["ShenPiSuoYouHeTong"] = userDt.Rows[0]["RY_ShenPiSuoYouHeTong"].ToString();// 存储审批所有合同
                foreach (DataRow row in userDt.Rows)                                  //处理记录集中的权限
                {
                    if (hs.Contains(row["QX_ID"].ToString()))
                    {
                        hs[row["QX_ID"].ToString()] = row["QX_ID"].ToString();
                    }
                    else
                    {
                        hs.Add(row["QX_ID"].ToString(),row["QX_ID"].ToString());
                    }
                }
                Session["QuanXian"] = hs;                     //将权限哈希表存在Session中
                string url = "SSRS";   //服务器名
                Session["Menu"] = menu.PaintingMenu(hs,url);  //根据权限哈希表和服务器名加载菜单
                String salesIds = "";
                if (DataSwitch.ConvertObjectToBoolean(userDt.Rows[0]["RY_ChaKanQuanBuDingDan"]))
                {
                    salesIds = "";
                    Session["RY_ChaKanQuanBuDingDan"] = true;
                }
                
            }
        }
        catch
        {
            Response.Write("fail");                        //操作失败打印fail
        }
    }
    public void write()
    {
        int a = 0;
    }
}

